package com.cwj.user.fieter;

import lombok.Setter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

@Setter
public class html_filter implements Filter {

    private com.cwj.user.dao.userDao userDao;
    private ServletContext servletContext;
    private Set<String> htmlSet;

    {
        htmlSet = new HashSet<>();
        htmlSet.add("error.html");
        htmlSet.add("login.html");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        HttpServletRequest request = (HttpServletRequest) servletRequest;
        String uri = request.getRequestURI();
        if (htmlSet.contains(uri.replace("/", ""))) {
            filterChain.doFilter(request, servletResponse);
            return;
        }

        userExists_filter.userExists(servletResponse, filterChain, request, userDao, servletContext);
    }
}
